import Vue from 'vue'
import App from './App'

Vue.config.productionTip = false

App.mpType = 'app'

// 引入全局uView
import uView from "uview-ui";
Vue.use(uView);

// Vue.prototype.$vconsole = new vconsole() // 使用vconsole
// util工具类
import util from "./utils/util.js"
Vue.prototype.util = util
// url
Vue.prototype.api = util.config().api
// md5加密
import md5 from "./utils/md5.js"
Vue.prototype.md5 = md5
// 支付密码校验 POST/mobileUser/password/pay支付密码校验
Vue.prototype.passwordCheck = function passwordCheck(password) {
	let userId = uni.getStorageSync("y-userId")
	var postObj = {
		url: '/mobileUser/password/pay',
		data: {
			password: password,
			userId: userId
		}
	};
	return new Promise((resolve, reject) => {
		this.postRequest(postObj)
			.then(res => {
				if (res.data.code == 200) {
					resolve()
				}
			})
			.catch(err => {
				reject()
			});
	})
}

// 请求 原生uni.request
import request from "./utils/request.js"
Vue.prototype.getRequest = request.getRequest
Vue.prototype.postRequest = request.postRequest
Vue.prototype.putRequest = request.putRequest


// 页面根据storage 展示loading
Vue.prototype.judgeLoading = function judgeLoading(options) {
	// http://192.168.0.156:8080/pages/transaction/transaction?token=111&userId=222
	// 先在首页获取信息
	if (!!options.token) uni.setStorageSync('y-token', options.token);
	if (!!options.userId) uni.setStorageSync('y-userId', options.userId);

	// 从storage拿信息
	let token = uni.getStorageSync('y-token');
	let userId = uni.getStorageSync('y-userId');

	// 没拿到信息展示loading
	uni.showLoading({
		title: '加载中...',
		mask: true
	});
	// 拿到信息隐藏loading  并  展示page  showPage
	if (!!token && !!userId) {
		uni.hideLoading();
		return true
	} else {
		return false
	}
}

const app = new Vue({
	...App
})
app.$mount()
